package com.example.demo.strategy;

/**
 * @author huchen
 * @description
 * @since 2022/1/5 15:57
 */
import org.apache.shardingsphere.elasticjob.infra.handler.sharding.JobInstance;
import org.springframework.stereotype.Component;
import java.util.Arrays;

/**
 * @author huchen
 * @description 自定义分片策略
 * @since 2021/12/20 10:25
 */
@Component
public final class ActiveStandbyESJobStrategy extends JobShardingStrategyActiveStandbyDecorator{
    @Override
    protected boolean isStandby(JobInstance jobInstance, String jobName) {
        String activeIps = "10.10.10.1,10.10.10.2";//只有这两个ip的实例才是优先执行的，其他都是备用的
        String ss[] = activeIps.split(",");
        return !Arrays.asList(ss).contains(jobInstance.getServerIp());//不在active名单的就是后备
    }

    @Override
    public String getType() {
        return "mytest";
    }
}
